<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>条件渲染</title>
	</head>
	<body>
		<div id="app">
			<template v-if="ok">
			  <h1>Title</h1>
			  <p>Paragraph 1</p>
			  <p>Paragraph 2</p>
			</template>
			
			<div v-if="type === 'A'">
				A
			</div>
			<div v-else-if="type === 'B'">
				B
			</div>
			<div v-else-if="type === 'C'">
				C
			</div>
			<div v-else="type === 'A'">
				Not A/B/C
			</div>
			
			<template v-if="loginType ==='username'">
				<label>Username</label>
				<input placeholder="Enter your username" key="username-input">
			</template>
			
			<template v-else>
				<label>Email</label>
				<input placeholder="Enter your email address" key="email-input">
			</template>
			<button v-on:click="changeLogin">切换登录</button>
		</div>
	</body>
	<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
	<script>
		var vm = new Vue({
			el:'#app',
			data:{
				ok:true,
				type:'D',
				loginType:'username',
			},
			methods:{
				changeLogin:function(){
					this.loginType = this.loginType == 'username' ? 'email' : 'username';
				}
			}
		})
	</script>
</html>